﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.RK.Controllers
{
    [ApiController, Area("RK"), Route("/[action]"), Customer_Admin]
    public class RK_ToolController : ControllerBase
    {
        private readonly Irk_tool_service _service;
        private readonly IToole_DI _tool;
        public RK_ToolController(Irk_tool_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }

        /// <summary>
        /// 销售新建客户
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/accountapi/sale_register")]
        public ResultModel SaleOnly_Register([FromForm] Entity.User user, [FromForm] string Sms, [FromForm] string roleid = "")
        {
            var result = _service.SaleOnly_Register(user, Sms, roleid);
            return result;
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/accountapi/register")]
        public ResultModel Register([FromForm] Entity.User user, [FromForm] string Sms, [FromForm] string roleid = "")
        {
            var result = _service.Register(user, Sms, roleid);
            return result;
        } 
        /// <summary>
        /// 获取机器列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/Admin/MchMana/getMchs")]
        public ResultModel getMchs([FromForm] getMchs_params query)
        {
            var result = _service.getMchs(query);
            return result;
        }
        /// <summary>
        /// 添加机器
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/admin/mchmana/create")]
        public ResultModel Create([FromForm]Entity.Mch model, [FromForm]List<Entity.Slot> slots)
        {
            var result = _service.Create(model, slots);
            return result;
        }

        /// <summary>
        /// 添加机器
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/Admin/MchMana/Edit")]
        public ResultModel Edit([FromForm]Entity.Mch model)
        {
            var result = _service.Edit(model);
            return result;
        }
        /// <summary>
        /// 获取simboss卡充值列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/Sys/SimBoss/get_simreg_list")]
        public ResultModel get_simreg_list([FromQuery]Base_PageList_Params query)
        {
            var result = _service.get_simreg_list(query);
            return result;
        }
        /// <summary>
        /// 支付开通状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/queryMerchantsSettle")]
        public ResultModel queryMerchantsSettle(string queryStartTime, string queryEndTime, string merchantNo = "", string orderStatus = "", int pageNum = 1, int pageSize = 50)
        {
            var result = _service.queryMerchantsSettle(queryStartTime, queryEndTime, merchantNo, orderStatus, pageNum, pageSize);
            return result;
        }
        /// <summary>
        /// 京东微信测商户信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/queryMerchantWXNo")]
        public ResultModel queryMerchantWXNo(string merchantNo)
        {
            var result = _service.queryMerchantWXNo(merchantNo);
            return result;
        }
         
        /// <summary>
        /// 结算查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/queryApplySingle")]
        public ResultObjExtModel queryApplySingle(string merchantNo)
        {
            var result = _service.queryApplySingle(merchantNo);
            return result;
        }
        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/querytrade")]
        public ResultModel querytrade(string order_id, string baseuserid)
        {
            var result = _service.querytrade(order_id, baseuserid);
            return result;
        }

        /// <summary>
        ///  退款查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/queryrefund")]
        public ResultModel queryrefund(string outRefundNo)
        {
            var result = _service.queryrefund(outRefundNo);
            return result;
        }

        /// <summary>
        /// 结算查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/start_rk_for_20200730")]
        public ResultModel start_rk_for_20200730()
        {
            var result = _service.start_rk_for_20200730();
            return result;
        }

        /// <summary>
        /// 结算查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/JD/ReApplySingle")]
        public ResultModel ReApplySingle(string merchantNo, string productid, string mfee = "0.6")
        {
            var result = _service.ReApplySingle(merchantNo, productid, mfee);
            return result;
        }

        /// <summary>
        /// 订单查询
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/search_order_model")]
        public ResultModel search_order_model(order_search_pagelist_Params query)
        {
            var result = _service.search_order_model(query);
            return result;
        } 
        /// <summary>
        /// 获取机器列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost("/get_mch_pagelist")]
        public ResultModel get_mch_pagelist(tool_get_mch_pagelist_query query)
        {
            var result = _service.get_mch_pagelist(query);
            return result;
        }

        /// <summary>
        /// 分配用户
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/distribution_user")]
        public ResultModel distribution_user(string userid, string mchid)
        {
            var result = _service.distribution_user(userid, mchid);
            _tool.di_es.Add_Log($"{(_tool.di_user.USER == null ? "??" : _tool.di_user.USER.uid + _tool.di_user.USER.u_name)}分配机器{mchid}到用户{userid}===>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "distribution_user");
            return result;
        }

        /// <summary>
        /// 编辑机器
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>NewEditMch
        [HttpPost("/NewEditMch")]
        public ResultModel NewEditMch(EditMch model)
        {
            var result = _service.NewEditMch(model);
            _tool.di_es.Add_Log($"{(_tool.di_user.USER == null ? "??" : _tool.di_user.USER.uid + _tool.di_user.USER.u_name)}修改机器信息{Newtonsoft.Json.JsonConvert.SerializeObject(model)}===>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "edit_mch");
            return result;
        }
        /// <summary>
        /// 分配用户
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet("/get_user_merchantNo")]
        public ResultModel get_user_merchantNo(string baseuserid)
        {
            var result = _service.get_user_merchantNo(baseuserid); 
            return result; 
        }
        /// <summary>
        /// 查询机器详情
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet("/search_mch")]

        public ResultObjModel search_mch(string keyword)
        {
            var result = _service.search_mch(keyword);
            return result;
        }

        /// <summary>
        /// 查询京东转账详情
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpPost("/get_jd_result")]

        public ResultObjExtModel get_jd_result(get_jd_result_params query)
        {
            var result = _service.get_jd_result(query);
            return result;
        }

        /// <summary>
        /// 查询京东转账详情
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet("/get_rk_user_forJd")]

        public ResultObjModel get_rk_user_forJd(string merchantNo)
        {
            var result = _service.get_rk_user_forJd(merchantNo);
            return result;
        }

        /// <summary>
        /// 修改指定用户id费率为6‰
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet("/rk_user_to_q6")]

        public ResultModel rk_user_to_q6(string id)
        {
           
            var result = _service.rk_user_to_q6(id);
            _tool.di_es.Add_Log($"{_tool.di_user.USER.u_name} {_tool.di_user.USER.uid}修改了用户{id}的京东手续费到6‰  请求结果=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "change_rate");
            return result;
        }

        /// <summary>
        ///  清洗截止到10月12日的数据信息
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet("/start_clear_run")]

        public ResultModel start_clear_run()
        {

            var result = _service.start_clear_run(); 
            return result;
        }

        /// <summary>
        ///  清洗截止到10月12日的数据信息
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpPost("/get_temp_list")]

        public ResultListModel<search_version_model> get_temp_list(search_temp_info query)
        { 
            var result = _service.get_temp_list(query);
            return result;
        }
        /// <summary>
        ///  清洗截止到10月12日的数据信息
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet("/end_temp")]

        public ResultModel end_temp(string mchid)
        {
            var result = _service.end_temp(mchid);
            return result;
        }
        /// <summary>
        ///  指定处理人
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpPost("/designated_person")]

        public ResultModel designated_person(designated_person_params Params)
        {
            var result = _service.designated_person(Params);
            _tool.di_es.Add_Log($"{_tool.di_user.USER.u_name}_{_tool.di_user.USER.uid}分配了就温控板处理人{Newtonsoft.Json.JsonConvert.SerializeObject(Params)}  请求结果=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "designated_person");
            return result;
        }
        /// <summary>
        ///  变更状态
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpPost("/change_state")]

        public ResultModel change_state(change_state_params Params)
        {
            var result = _service.change_state(Params.mchid, Params.diy_remark, Params.state);
            _tool.di_es.Add_Log($"{_tool.di_user.USER.u_name}_{_tool.di_user.USER.uid}变更了状态{Newtonsoft.Json.JsonConvert.SerializeObject(Params)}  请求结果=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "designated_person");
            return result;
        } 
    }
}